home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / utils / xad / developer / sources / clients / xpkstuff.c < prev   
C/C++ Source or Header  |  1999-01-01  |  3KB  |  112 lines

  1. #ifndef XADMASTER_XPKSTUFF_C
  2. #define XADMASTER_XPKSTUFF_C
  3.  
  4. /* Programmheader
  5.  
  6.     Name:        xpkstuff.c
  7.     Main:        xadmaster
  8.     Versionstring:    $VER: xpkstuff.c 1.1 (10.08.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    xpk decrunch handling
  12.  
  13.  1.0   14.06.98 : first version
  14.  1.1   10.08.98 : completed xpkDecrunch
  15. */
  16.  
  17. #include <proto/xpkmaster.h>
  18. #include <proto/xadmaster.h>
  19. #include <proto/exec.h>
  20. #include <exec/memory.h>
  21.  
  22. LONG GetXpkError(LONG err);
  23.  
  24. /* reads XPKF file from current input stream and stores a pointer to
  25. decrunched file in *str and the size in *size */
  26. LONG xpkDecrunch(STRPTR *str, ULONG *size, struct xadArchiveInfo *ai,
  27. struct xadMasterBase *xadMasterBase)
  28. {
  29.   struct Library *XpkBase;
  30.   struct ExecBase * SysBase = xadMasterBase->xmb_SysBase;
  31.   ULONG buf[2];
  32.   LONG err;
  33.   ULONG *mem;
  34.   
  35.   if((XpkBase = OpenLibrary("xpkmaster.library", 4)))
  36.   {
  37.     if(!(err = xadHookAccess(XADAC_READ, 8, buf, ai)))
  38.     {
  39.       if((mem = AllocMem(buf[1]+8, MEMF_PUBLIC)))
  40.       {
  41.         if(!(err = xadHookAccess(XADAC_READ, buf[1], mem+2, ai)))
  42.         {
  43.           struct XpkFib xfib;
  44.  
  45.           mem[0] = buf[0];
  46.           mem[1] = buf[1];
  47.  
  48.           if(!XpkExamineTags(&xfib, XPK_InBuf, mem,
  49.           XPK_InLen, buf[1]+8, TAG_DONE))
  50.           {
  51.             STRPTR mem2;
  52.  
  53.         if((mem2 = (STRPTR) AllocVec(xfib.xf_ULen+XPK_MARGIN,
  54.         MEMF_PUBLIC|MEMF_CLEAR)))
  55.         {
  56.           *str = mem2;
  57.           *size = xfib.xf_ULen;
  58.  
  59.               if((err = GetXpkError(XpkUnpackTags(XPK_InBuf, mem,
  60.               XPK_InLen, buf[1]+8, XPK_OutBuf, mem2, XPK_OutBufLen,
  61.               *size + XPK_MARGIN, ai->xai_Password ? XPK_Password :
  62.               TAG_IGNORE, ai->xai_Password, XPK_UseXfdMaster, 0,
  63.               XPK_PassRequest, FALSE, TAG_DONE))))
  64.               {
  65.                 FreeVec(mem2); *str = 0; *size = 0;
  66.               }
  67.             }
  68.           }
  69.           else
  70.             err = XADERR_ILLEGALDATA;
  71.         }  
  72.         FreeMem(mem, buf[1]+8);
  73.       } /* AllocMem */
  74.       else
  75.         err = XADERR_NOMEMORY;
  76.     } /* Hook Read */
  77.     CloseLibrary(XpkBase);
  78.   } /* OpenLibrary */
  79.   else
  80.     err = XADERR_RESOURCE;
  81.  
  82.   return err;
  83. }
  84.  
  85. LONG GetXpkError(LONG err)
  86. {
  87.   LONG ret;
  88.  
  89.   switch(err)
  90.   {
  91.     case XPKERR_OK:        ret = XADERR_OK; break;
  92.     case XPKERR_IOERRIN:    ret = XADERR_INPUT; break;
  93.     case XPKERR_IOERROUT:    ret = XADERR_OUTPUT; break;
  94.     case XPKERR_CORRUPTPKD:
  95.     case XPKERR_TRUNCATED:    ret = XADERR_ILLEGALDATA; break;
  96.     case XPKERR_NOMEM:        ret = XADERR_NOMEMORY; break;
  97.     case XPKERR_WRONGCPU:
  98.     case XPKERR_MISSINGLIB:
  99.     case XPKERR_VERSION:
  100.     case XPKERR_OLDMASTLIB:
  101.     case XPKERR_OLDSUBLIB:
  102.     case XPKERR_NOHARDWARE:
  103.     case XPKERR_BADHARDWARE:    ret = XADERR_RESOURCE; break;
  104.     case XPKERR_NEEDPASSWD:
  105.     case XPKERR_WRONGPW:    ret = XADERR_PASSWORD; break;
  106.     default:            ret = XADERR_DECRUNCH; break;
  107.   };
  108.   return ret;
  109. }
  110.  
  111. #endif /* XADASTER_XPKDECRUNCH_C */
  112.